<template>
  <div class="app-container">
    <el-form
      v-show="showSearch"
      ref="queryForm"
      :model="queryParams"
      size="small"
      :inline="true"
      label-width="80px"
    >
      <el-form-item label="人员类型" prop="type">
        <el-select
          v-model="queryParams.type"
          placeholder="请选择人员类型"
          clearable
        >
          <el-option
            v-for="dict in dict.type.user_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="所属地区" prop="area">
        <area-cascader v-model="queryParams.area" />
      </el-form-item>
      <el-form-item label="姓名" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="身份证号码" prop="idno" label-width="100px">
        <el-input
          v-model="queryParams.idno"
          placeholder="请输入身份证号码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['user:zdgz:add']"
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['user:zdgz:edit']"
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          >修改</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['user:zdgz:remove']"
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          >删除</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['user:zdgz:export']"
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          >导出</el-button
        >
      </el-col>
      <right-toolbar :show-search.sync="showSearch" @queryTable="getList" />
    </el-row>

    <el-table
      v-loading="loading"
      :data="zdgzList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="人员类型" align="center" prop="type">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.user_type" :value="scope.row.type" />
        </template>
      </el-table-column>
      <el-table-column label="所属地区" align="center" prop="areaName" />
      <el-table-column label="姓名" align="center" prop="name" />
      <el-table-column label="性别" align="center" prop="gender">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.gender" :value="scope.row.gender" />
        </template>
      </el-table-column>
      <el-table-column label="民族" align="center" prop="mz" />
      <el-table-column label="政治面貌" align="center" prop="zzmm">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.zzmm" :value="scope.row.zzmm" />
        </template>
      </el-table-column>
      <el-table-column label="身高" align="center" prop="height" />
      <el-table-column label="身份证号码" align="center" prop="idno" />
      <el-table-column
        label="出生日期"
        align="center"
        prop="birthday"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.birthday, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column label="文化程度" align="center" prop="whcd">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.whcd" :value="scope.row.whcd" />
        </template>
      </el-table-column>
      <el-table-column label="就业情况" align="center" prop="jyqk">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.jyqk" :value="scope.row.jyqk" />
        </template>
      </el-table-column>
      <el-table-column label="固定电话" align="center" prop="gddh" />
      <el-table-column label="本人移动电话" align="center" prop="mobile" />
      <el-table-column label="婚姻状况" align="center" prop="hyzk">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.hyzk" :value="scope.row.hyzk" />
        </template>
      </el-table-column>
      <el-table-column label="目前状态" align="center" prop="mqzt">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.mqgzzt" :value="scope.row.mqzt" />
        </template>
      </el-table-column>
      <el-table-column label="是否与父母居住" align="center" prop="sfyfmzj">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_yes_no" :value="scope.row.sfyfmzj" />
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            v-hasPermi="['user:zdgz:edit']"
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            >修改</el-button
          >
          <el-button
            v-hasPermi="['user:zdgz:remove']"
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { listUser, delUser } from "@/api/user/userInfo";

export default {
  name: "Zdgz",
  dicts: [
    "user_type",
    "hyzk",
    "mqgzzt",
    "whcd",
    "lydplx",
    "sys_yes_no",
    "gender",
    "jntc",
    "jyqk",
    "zzmm",
  ],
  data() {
    return {
      // 按钮loading
      buttonLoading: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 重点关注人员表格数据
      zdgzList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        subType: 'drug_zdgz',
        pageNum: 1,
        pageSize: 10,
        mgrUserId: undefined,
        type: undefined,
        area: undefined,
        name: undefined,
        gender: undefined,
        mz: undefined,
        zzmm: undefined,
        height: undefined,
        idno: undefined,
        birthday: undefined,
        whcd: undefined,
        hjdpcs: undefined,
        hjd: undefined,
        hjdxz: undefined,
        jzdpcs: undefined,
        jzd: undefined,
        fzr: undefined,
        jyqk: undefined,
        gddh: undefined,
        bryddh: undefined,
        hyzk: undefined,
        mqzt: undefined,
        sfyfmjz: undefined,
        jzdxz: undefined,
        ysdabh: undefined,
        ssjwq: undefined,
        lydpzl: undefined,
        jntc: undefined,
        fxdj: undefined,
      },
      // 表单参数
      form: {},
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询重点关注人员列表 */
    getList() {
      this.loading = true;
      listUser(this.queryParams).then((response) => {
        this.zdgzList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        subType: 'drug_zdgz',
        id: undefined,
        mgrUserId: undefined,
        type: undefined,
        area: undefined,
        name: undefined,
        gender: undefined,
        mz: undefined,
        zzmm: undefined,
        height: undefined,
        idno: undefined,
        birthday: undefined,
        whcd: undefined,
        hjdpcs: undefined,
        hjd: undefined,
        hjdxz: undefined,
        jzdpcs: undefined,
        jzd: undefined,
        fzr: undefined,
        jyqk: undefined,
        gddh: undefined,
        bryddh: undefined,
        hyzk: undefined,
        mqzt: undefined,
        sfyfmjz: undefined,
        jzdxz: undefined,
        ysdabh: undefined,
        ssjwq: undefined,
        lydpzl: undefined,
        jntc: undefined,
        fxdj: undefined,
        createBy: undefined,
        createTime: undefined,
        updateBy: undefined,
        updateTime: undefined,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.zdgzId);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.$router.push({ path: "/user/zdgz-detail/index" });
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      const zdgzId = row.id || this.ids;
      this.$router.push({
        path: "/user/zdgz-detail/index",
        query: { zdgzId: zdgzId },
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const zdgzIds = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除重点关注人员编号为"' + zdgzIds + '"的数据项？')
        .then(() => {
          this.loading = true;
          return delUser(zdgzIds);
        })
        .then(() => {
          this.loading = false;
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {})
        .finally(() => {
          this.loading = false;
        });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "user/zdgz/export",
        {
          ...this.queryParams,
        },
        `zdgz_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
